package com.mf.controller;

import com.mf.entity.bo.DataDictionaryBo;
import com.mf.entity.request.dataDictionary.DataDictionaryRequest;
import com.mf.entity.vo.DataDictionaryVo;
import com.mf.result.Result;
import com.mf.service.IDataDictionaryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;


/**
 * @author mf
 * @since 2024-07-19
 */
@Tag(name = "数据字典模块")
@RestController
@RequestMapping("api/dataDictionary/v1")
public class DataDictionaryController {
    @Resource
    private IDataDictionaryService dataDictionaryService;

    @Operation(summary = "新增字典值")
    @PostMapping("add")
    public Result<Integer> add(@Valid @RequestBody DataDictionaryRequest dataDictionaryRequest) {
        return Result.success(dataDictionaryService.add(dataDictionaryRequest));
    }

    @Operation(summary = "删除字典")
    @GetMapping("deleteById")
    public Result<Boolean> deleteById(@RequestParam("id") Integer id) {
        return Result.success(dataDictionaryService.removeById(id));
    }

    @Operation(summary = "批量删除字典")
    @PostMapping("deleteByIds")
    public Result<Boolean> deleteByIds(@RequestBody Integer[] ids) {
        return Result.success(dataDictionaryService.removeBatchByIds(Arrays.asList(ids)));
    }

    @Operation(summary = "编辑数据字典")
    @PostMapping("edit")
    public Result<Integer> edit(@RequestBody DataDictionaryRequest dataDictionaryRequest) {
        return Result.success(dataDictionaryService.edit(dataDictionaryRequest));
    }

    @Operation(summary = "根据id查询字典")
    @GetMapping("findById")
    public Result<DataDictionaryVo> findById(@RequestParam("id") Integer id) {
        return Result.success(dataDictionaryService.findById(id));
    }

    @Operation(summary = "根据编号查询")
    @GetMapping("findByCode")
    public Result<List<DataDictionaryVo>> findByCode(@RequestParam("code") String code) {
        return Result.success(dataDictionaryService.findByCode(code));
    }

}
